package src.unapec.security.models.EntornoJava;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FilePermission;
import java.io.FileWriter;
import java.io.IOException;

public class Permisos {
	
	private FilePermission permission = null;
	private String path = "/home/rmatos/Desktop/Seguridad/", actions = "read";
	
	//permission java.util.PropertyPermission "user.home", "read";
	//permission java.io.FilePermission "${user.home}${/}caos${/}" , "read,write";
	//permission java.io.FilePermission "${user.home}${/}caos${/}*" , "read,write";
	//permission java.io.FilePermission "${user.home}${/}determinista${/}" , "read,write";
	//permission java.io.FilePermission "${user.home}${/}determinista${/}*" , "read,write";
	
	public void write(){		
				
		try {
			
			StringBuffer sb = new StringBuffer();
			
			File file = new File(path);
			file.setWritable(true);//permission = new FilePermission(path,actions);
			
			//static private FileSystem fs = FileSystem.getFileSystem();
			
		    //public boolean setReadOnly() {
			//SecurityManager security = System.getSecurityManager();
			//if (security != null) {
			//security.checkWrite(path);
			//}
			//return fs.setReadOnly(this);
			//}			
			
			BufferedWriter bw = new BufferedWriter(new FileWriter(file+"/Testing.txt"));
						
			sb.append("This is only a test 1");			
			bw.write(sb.toString());
			
			bw.close();
			
		} catch (IOException e) {
			
			System.out.println(e.getMessage());
			System.out.println("Error");
		
		}		
		
		System.out.println("Done");
		
		
	}
	
	public static void main(String[] args) {
		
		
		Permisos permisos = new Permisos();
		permisos.write();
		
		
	}
	
	
}
